/**
 * 
 */
package com.feib.stms.action;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontBind;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.integration.spring.SpringBean;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import com.feib.stms.model.Group;
import com.feib.stms.model.LabelValue;
import com.feib.stms.model.Securities;
import com.feib.stms.model.TempUser;
import com.feib.stms.model.User;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.service.GroupService;
import com.feib.stms.service.SecuritiesService;
import com.feib.stms.service.TempUserService;
import com.feib.stms.service.UserService;
import com.feib.stms.util.UserUtil;

/**
 * @title (#)Stms9006ActionBean.java<br>
 * @description 使用者資料維護 <br>
 * @author Lion Gao<br>
 * @version 
 * @copyright Far Eastern International Bank Copyright (c) 2012<br>
 * @2012/06/04 create by Lion Gao<br>
 *
 */
public class Stms9006ActionBean extends BaseActionBean 
{
	private static final long serialVersionUID = -3360927795653829350L;

	private static final String DEFAULT_JSP = "/WEB-INF/views/stms9006/stms9006.jsp";
	private static final String DETAIL_JSP = "/WEB-INF/views/stms9006/stms9006Detail.jsp";
	private static final String CREATE_JSP = "/WEB-INF/views/stms9006/stms9006Create.jsp";
	
	/*畫面sortHeader傳回來的值*/
	private static List<String> SORT_KEYS = new ArrayList<String>();
	static{
		SORT_KEYS.add("userId".toLowerCase());
		SORT_KEYS.add("userName".toLowerCase());
		SORT_KEYS.add("userPhoneNo".toLowerCase());
		SORT_KEYS.add("userEmail".toLowerCase());
		SORT_KEYS.add("userLoginControl".toLowerCase());
	}

	/*使用SORT_KEYS作key值取得對應的資料庫欄位名稱*/
	private static Map<String,String> SORT_FIELD =  new HashMap<String, String>();
	static{
		SORT_FIELD.put("userId".toLowerCase(), "USER_ID");
		SORT_FIELD.put("userName".toLowerCase(), "USER_NAME");
		SORT_FIELD.put("userPhoneNo".toLowerCase(), "USER_PHONE_NO");
		SORT_FIELD.put("userEmail".toLowerCase(), "USER_EMAIL");
		SORT_FIELD.put("userLoginControl".toLowerCase(), "nvl(IS_ACTIVED,0)");
	}

	/** 
	 * 查詢條件-使用者ID
	 */
	private String qryUserIdForm;
	
	/** 
	 * 查詢條件-姓名
	 */
	private String qryUserNameForm;
	
	 /**
     * 查詢結果(多筆)
     */
    private PaginatedList<User> queryResult;
    
    /**
     * 更新-綁定查詢條件-使用者帳號
     */
    private String qryUserId;
    /**
     * 更新-綁定bean
     */
    private User editUser;
    
    /**
     * 用於顯示APP_USER中資料，在修改時候用於畫面對比顯示
     */
    private User showEditUser;
    
    /**
     * 用於顯示APP_USER中資料，在修改時候用於畫面對比顯示 --顯示可處理資料
     */
    private List<LabelValue> showDealSecuritiesNos;
    /**
     * 新增-綁定bean
     */
    private User createUser;
    
    /**
     * 可處理券商資料列表 --獲取分公司
     */
    private Collection<LabelValue> dealSecuritiesNos;
    
    /**
     * 可處理券商資料-綁定
     */
    private List<String> qryDealSecuritiesNos;
    
    /**
     * 所屬分公司列表
     */
    private List<Securities> securitiesOptionList;
	
	/**
	 * 執行結果訊息
	 */
	private String message;
	
	/**
	 * 新增權限
	 */
	private Boolean created;
	
	 /**
     * 標記新增或修改
     */
    private String operation;
    
    /**
     * 用於鑒別修改使用者時候，執行新增還是修改動作
     */
    private String confirmIfTemp;
    
    /**
     * 使用者所屬groupPk 
     */
    private Long qryGroupPk;
    
    @SpringBean("userService")
	private UserService userService;
    
    @SpringBean("tempUserService")
	private TempUserService tempUserService;
	
	@SpringBean("securitiesService")
	private SecuritiesService securitiesService;
	
	@SpringBean("groupService")
    private GroupService groupService;
	
	@DontBind
	@DefaultHandler
	public Resolution doDefault()
	{
		logger.debug("Enter doDefault mehtod.");
		//進行權限判定
		if(UserUtil.isAdminRole()){
			created = true;
		}
		if(!UserUtil.isBankGroup() && !UserUtil.isAdminRole()){
			created = false;
		}
		return new ForwardResolution(DEFAULT_JSP); 
	}

	/**
	 * 查詢
	 * @return
	 */
	public Resolution doQuery()
	{
		logger.debug("Enter doQuery mehtod.");
		//進行權限判定
		if(UserUtil.isAdminRole()){
			created = true;
		}
		if(!UserUtil.isBankGroup() && !UserUtil.isAdminRole()){
			created = false;
		}
		/* 設定換頁、排序等條件*/
		String sortCriterion = "userId";
		int sortDirection = 1;
		PaginatedList<User> qryCondition = new PaginatedList<User>();
		if (null != queryResult)
		{	
			//畫面傳入的排序字段
			sortCriterion = queryResult.getSortCriterion();
			sortDirection = queryResult.getSortDirection();
			//分頁
			qryCondition.setPageNumber(queryResult.getPageNumber());
			qryCondition.setPageSize(queryResult.getPageSize());
			//將畫面傳入的排序字段轉換為資料庫對應的字段
			String StringSortCriterion = SORT_FIELD.get(sortCriterion.toLowerCase());
			//設置排序
			qryCondition.setSortCriterion(StringSortCriterion);
			qryCondition.setSortDirection(sortDirection);
			logger.debug(" qryCondition:sortCriterion={}  sortDirection={} ", new Object[]{qryCondition.getSortCriterion(), qryCondition.getSortDirection()});
			
		}
		/*沒有設定排序就以第一欄作排序條件*/
		if (null == queryResult || StringUtils.isEmpty(queryResult.getSortCriterion()) || !SORT_KEYS.contains(queryResult.getSortCriterion().toLowerCase()))
		{
			qryCondition.setSortCriterion(SORT_FIELD.get(SORT_KEYS.get(0)));
		}
		
		/* 設定查詢條件*/
		User qryUser = new User();
		qryUser.setUserId(qryUserIdForm);
		qryUser.setUserName(qryUserNameForm);
		//調用service,到資料庫撈取DB
		this.queryResult = userService.queryByUser(qryUser, qryCondition);

		if (null == this.queryResult)
			this.queryResult = qryCondition;
		
		queryResult.setSortCriterion(sortCriterion);
		queryResult.setSortDirection(sortDirection);

		if (CollectionUtils.isEmpty(this.queryResult.getPaginatedList()))
			this.message = "查無資料！";

		return new ForwardResolution(DEFAULT_JSP); 
	}

	/**
	 * 檢視使用者
	 * @return
	 */
	public Resolution doUpdate()
	{
		logger.debug("Enter doUpdate mehtod.");
		this.operation = "update";
		/*先檢查此帳號是否已經有修改紀錄(檢查temp_user是否有待放行資料)，有未放行資料時就撈取temp_user做為資料基準，沒有就撈取user。
		 * 修改使用者資料時一樣將USER的資料複製一份放在temp_user中，待放行後才正式更新user的資料。  
		 */
		//1.檢查temp_user是否有待放行資料
		TempUser tempUser = this.tempUserService.findByTempUerId(this.qryUserId , qryGroupPk);
		if(tempUser != null){//有待放行資料
			this.showEditUser = this.userService.findByUerId(this.qryUserId, qryGroupPk);
			this.editUser = tempUser.getUser();
			this.editUser.setUserLoginControl(showEditUser.getUserLoginControl());
			this.editUser.setLastLoginDate(showEditUser.getLastLoginDate());
			//處理畫面顯示可處理資料比對資料
			this.showDealSecuritiesNos = new ArrayList<LabelValue>();
			String tempDealSecuritiesNos = editUser.getDealSecuritiesNos();
			List<String> tempDealSecuritiesNo = new ArrayList<String>();
			if(StringUtils.isNotEmpty(tempDealSecuritiesNos)){
				String[] abs = tempDealSecuritiesNos.split(",");
				for(String securitiesNo:abs){
					if(null != securitiesNo){
						tempDealSecuritiesNo.add(securitiesNo);
					}
				}
			}
			/* 調用查詢方法 */
			/* 分公司查詢結果 */
			List<Securities> tempBranch = new ArrayList<Securities>();
	        try {
	        	tempBranch = securitiesService.findForSecuritiesListBySecuritiesNos(tempDealSecuritiesNo);
			} catch (Exception e) {
				tempBranch = null;
				logger.debug("Error in doUpdate() method when login user is normal user for find for securities list by group Pk!");
			}
			if(null != tempBranch && tempBranch.size()>0){
				//分公司查詢結果長度
				int j = tempBranch.size();
				for(int i = 0; i < j; i++){
					LabelValue labelValue = new LabelValue();
					labelValue.setLabel(tempBranch.get(i).getSecuritiesName());
					labelValue.setValue(tempBranch.get(i).getSecuritiesPk().toString());
					this.showDealSecuritiesNos.add(labelValue);
				}
			}
			this.confirmIfTemp = "update";
		}else{//無待放行資料
			this.editUser = this.userService.findByUerId(this.qryUserId ,qryGroupPk);
			
			if(editUser == null){
				message = "使用者不存在!";
				return new ForwardResolution(DEFAULT_JSP); 
			}
			this.confirmIfTemp = "create";
		}
		return new ForwardResolution(DETAIL_JSP); 
	}
	
	 /**
     * 跳轉新增畫面
     * @return
     */
    public Resolution doCreate()
    {	
    	logger.debug("Enter doCreate mehtod.");
    	this.operation = "create";
    	return new ForwardResolution(CREATE_JSP); 
    }
    
	 /**
     * 確認
     * @return
     */
    public Resolution doSave()
    {	
    	logger.debug("Enter doSave mehtod.");
    	try{
    		if(this.operation != null && this.operation.equals("create")){
        		//獲取登陸者
            	User user = UserUtil.getUser();
        		//查詢APP_USER,使用者ID是否重複
                int countResult = userService.countUserId(createUser.getUserId(),user.getGroup().getGroupPk());
                //查詢TEMP_USER,未放行的使用者ID是否重複
                int countTempResult = tempUserService.countTempUserId(createUser.getUserId(),user.getGroup().getGroupPk());
                if(countResult > 0 || countTempResult > 0){
                	message = "新增失敗,使用者ID重複!";
                }else{
                	//將User 轉變為 TempUser     
                	Group group = new Group();
                	group.setGroupPk(user.getGroup().getGroupPk());
                	TempUser tempUser = new TempUser();
                	createUser.setGroup(group);//群組
                	createUser.setUserPwd("4a7d1ed414474e4033ac29ccb8653d9b");//default pwd: 0000
                	createUser.setCreatedBy(user.getGroup().getGroupNo() + "_" +user.getUserId());//操作者
                	createUser.setCreatedDate(new Date());//操作日期
                	createUser.setPwdExpiredDate(new Date()); // 強迫下次登入要變更密碼
                	//可處理券商
                	if(qryDealSecuritiesNos != null && qryDealSecuritiesNos.size() > 0){
                		createUser.setDealSecuritiesNos(getStringFromList(qryDealSecuritiesNos));
                	}                	
                	tempUser.setUser(createUser);
                	tempUser.setConfirmStatus(null);//放行狀態 null: 待放行 Y: 放行 N: 退回
                	tempUser.setRecordStatus(TempUser.USER_RECORD_SATAUS_ADD_MODE);//交易紀錄狀態 -新增
                	int insertCount = tempUserService.saveTempUser(tempUser);
                	message = insertCount > 0?"新增使用者成功,待管理者放行！":"新增失敗!";
                	if(insertCount > 0){//新增成功，則跳轉到查詢畫面
                		return doQuery();
                	}
                }
            	return new ForwardResolution(CREATE_JSP); 
        	}else if(this.operation != null && this.operation.equals("update")){
        		//獲取登陸者
            	User user = UserUtil.getUser();
        		if(this.confirmIfTemp != null && this.confirmIfTemp.equals("create")){
        			//將User 轉變為 TempUser
                	TempUser tempUser = new TempUser();
                	editUser.setUserPwd("4a7d1ed414474e4033ac29ccb8653d9b");//default pwd: 0000
                	editUser.setCreatedBy(user.getGroup().getGroupNo() + "_" +user.getUserId());//操作者
                	editUser.setCreatedDate(new Date());//操作日期
                	editUser.setPwdExpiredDate(new Date()); // 強迫下次登入要變更密碼
                	//可處理券商
                	if(qryDealSecuritiesNos != null && qryDealSecuritiesNos.size() > 0){
                		editUser.setDealSecuritiesNos(getStringFromList(qryDealSecuritiesNos));
                	}
                	tempUser.setUser(editUser);
                	tempUser.setConfirmStatus(null);//放行狀態 null: 待放行 Y: 放行 N: 退回
                	tempUser.setRecordStatus(TempUser.USER_RECORD_SATAUS_UPDATE_MODE);//交易紀錄狀態 --修改
                	int insertCount = tempUserService.saveTempUser(tempUser);
                	message = insertCount > 0?"修改使用者成功,待管理者放行！":"修改失敗!";
                	if(insertCount > 0){//更新成功，則跳轉到查詢畫面
                		return doQuery();
                	}
                    return new ForwardResolution(DETAIL_JSP); 
        		}else if(this.confirmIfTemp != null && this.confirmIfTemp.equals("update")){
        			//去db查詢該筆使用者資料
        			TempUser tempUser = tempUserService.findByTempUerId(editUser.getUserId(),editUser.getGroup().getGroupPk());
        			//將畫面中user的值賦予tempUser
        			User temp =  tempUser.getUser();
        			temp.setUserId(editUser.getUserId());
        			temp.setUserName(this.editUser.getUserName());
        			temp.setUserPhoneNo(this.editUser.getUserPhoneNo());
        			temp.setUserEmail(this.editUser.getUserEmail());
        			temp.setEnabled(this.editUser.getEnabled());
        			temp.setLocked(this.editUser.getLocked());
        			temp.setCertificateKey(this.editUser.getCertificateKey());
        			temp.setUserNote(this.editUser.getUserNote());
        			temp.setDealSecuritiesNos(getStringFromList(this.getQryDealSecuritiesNos()));
        			temp.setGroup(editUser.getGroup());//否則，獲取畫面的group
        			temp.setSecurities(this.editUser.getSecurities());
        			temp.setUpdatedBy(user.getGroup().getGroupNo() + "_" + user.getUserId());
        			temp.setUpdatedDate(new Date());
        			temp.setSecurities(editUser.getSecurities());
        			tempUser.setUser(temp);
        			tempUser.setRecordStatus(TempUser.USER_RECORD_SATAUS_UPDATE_MODE);//交易紀錄狀態 --修改
        			tempUser.setConfirmStatus(null);//放行狀態 null: 待放行 Y: 放行 N: 退回
                	int insertCount = tempUserService.updateTempUser(tempUser);
                	message = insertCount > 0?"修改使用者成功,待管理者放行！":"修改失敗!";
                	if(insertCount > 0){//更新成功，則跳轉到查詢畫面
                		return doQuery();
                	}
                    return new ForwardResolution(DETAIL_JSP); 
        		}
        		
        	}
    	}catch(Exception e){
    		logger.error("使用者資料維護(Stms9006ActionBean.doSave):", e);
    	}
    	return doQuery();
    }
    
    /**
     * 取消
     * @return
     */
    public Resolution doCancel()
    {
    	logger.debug("Enter doCancel mehtod.");
    	return doQuery();
    }
    
	/**
	 * @return created
	 */
	public Boolean getCreated() {
		return created;
	}

	/**
	 * @param created 的設定的 created
	 */
	public void setCreated(Boolean created) {
		this.created = created;
	}

	/**
	 * @return createUser
	 */
	public User getCreateUser() {
		return createUser;
	}

	/**
	 * @param createUser 的設定的 createUser
	 */
	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}
	
	/**
	 * @return showDealSecuritiesNos
	 */
	public List<LabelValue> getShowDealSecuritiesNos() {
		return showDealSecuritiesNos;
	}

	/**
	 * @param showDealSecuritiesNos 的設定的 showDealSecuritiesNos
	 */
	public void setShowDealSecuritiesNos(List<LabelValue> showDealSecuritiesNos) {
		this.showDealSecuritiesNos = showDealSecuritiesNos;
	}

	/**
	 * @return qryDealSecuritiesNos
	 */
	public List<String> getQryDealSecuritiesNos() {
		return qryDealSecuritiesNos;
	}

	/**
	 * @param qryDealSecuritiesNos 的設定的 qryDealSecuritiesNos
	 */
	public void setQryDealSecuritiesNos(List<String> qryDealSecuritiesNos) {
		this.qryDealSecuritiesNos = qryDealSecuritiesNos;
	}

	/**
	 * @return dealSecuritiesNos
	 */
	public Collection<LabelValue> getDealSecuritiesNos() {
		/* 是否為銀行群組 */
		boolean isBankGroup = UserUtil.isBankGroup();
		/* 分公司查詢結果 */
		List<Securities> tempBranch = new ArrayList<Securities>();
		/* 如果不是銀行群組，則獲取登陸者當前帳號可處理券商的資料 */
		if(!isBankGroup){
			//獲取當前登錄用戶
			User user = UserUtil.getUser();
			//取得當前登錄用戶的可處理券商資料
			String userGroupPk = user.getGroup().getGroupPk().toString();
			//取得當前選擇處理券商的資料
			List<String> tempUserGroupPk = new ArrayList<String>();
			tempUserGroupPk.add(userGroupPk);
			/* 調用查詢 */
			try {
				tempBranch = securitiesService.findForSecuritiesListByGroupPks(tempUserGroupPk);
			} catch (Exception e) {
				tempBranch = null;
				logger.debug("Error in getDealSecuritiesNos() method when login user is bank group for find for securities list by group Pk!");
			}
		}
		/* 如果是銀行群組，則可以查詢所有分公司的資料 */
		else{
			/* 調用查詢 */
			tempBranch = securitiesService.findForListBySecurities();
		}
		this.dealSecuritiesNos = new ArrayList<LabelValue>();
		if(!CollectionUtils.isEmpty(tempBranch) && tempBranch.size() > 0){
			for(Securities s:tempBranch){
				LabelValue labelValue = new LabelValue();
				labelValue.setLabel(s.getSecuritiesName());
				labelValue.setValue(s.getSecuritiesNo());
				dealSecuritiesNos.add(labelValue);
			}
		}
		//修改使用
		if(this.editUser != null){
			String strDealSecuritiesNos = this.editUser.getDealSecuritiesNos();//db中的可處理資料
			if(!StringUtils.isEmpty(strDealSecuritiesNos)){
				if(dealSecuritiesNos != null && dealSecuritiesNos.size() > 0){
					for(LabelValue l:dealSecuritiesNos){
						if(strDealSecuritiesNos.contains(l.getValue())){
							l.setChecked(true);
						}else{
							l.setChecked(false);
						}
					}
				}
			}
		}
		return dealSecuritiesNos;
	}

	/**
	 * @param dealSecuritiesNos 的設定的 dealSecuritiesNos
	 */
	public void setDealSecuritiesNos(Collection<LabelValue> dealSecuritiesNos) {
		this.dealSecuritiesNos = dealSecuritiesNos;
	}

	/**
	 * @return editUser
	 */
	public User getEditUser() {
		return editUser;
	}

	/**
	 * @param editUser 的設定的 editUser
	 */
	public void setEditUser(User editUser) {
		this.editUser = editUser;
	}
	
	/**
	 * @return showEditUser
	 */
	public User getShowEditUser() {
		return showEditUser;
	}

	/**
	 * @param showEditUser 的設定的 showEditUser
	 */
	public void setShowEditUser(User showEditUser) {
		this.showEditUser = showEditUser;
	}

	/**
	 * @return message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message 的設定的 message
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return operation
	 */
	public String getOperation() {
		return operation;
	}

	/**
	 * @param operation 的設定的 operation
	 */
	public void setOperation(String operation) {
		this.operation = operation;
	}

	/**
	 * @return qryUserIdForm
	 */
	public String getQryUserIdForm() {
		return qryUserIdForm;
	}

	/**
	 * @param qryUserIdForm 的設定的 qryUserIdForm
	 */
	public void setQryUserIdForm(String qryUserIdForm) {
		this.qryUserIdForm = qryUserIdForm;
	}

	/**
	 * @return qryUserNameForm
	 */
	public String getQryUserNameForm() {
		return qryUserNameForm;
	}

	/**
	 * @param qryUserNameForm 的設定的 qryUserNameForm
	 */
	public void setQryUserNameForm(String qryUserNameForm) {
		this.qryUserNameForm = qryUserNameForm;
	}
	
	/**
	 * @return qryUserId
	 */
	public String getQryUserId() {
		return qryUserId;
	}

	/**
	 * @param qryUserId 的設定的 qryUserId
	 */
	public void setQryUserId(String qryUserId) {
		this.qryUserId = qryUserId;
	}

	/**
	 * @return queryResult
	 */
	public PaginatedList<User> getQueryResult() {
		return queryResult;
	}

	/**
	 * @param queryResult 的設定的 queryResult
	 */
	public void setQueryResult(PaginatedList<User> queryResult) {
		this.queryResult = queryResult;
	}

	/**
	 * @return securitiesOptionList
	 */
	public List<Securities> getSecuritiesOptionList() {
		if(null == this.securitiesOptionList){
			/* 是否為銀行群組 */
			boolean isBankGroup = UserUtil.isBankGroup();
			/* 分公司查詢結果 */
			/* 如果不是銀行群組，則獲取登陸者當前帳號可處理券商的資料 */
			if(!isBankGroup){
				//獲取當前登錄用戶
				User user = UserUtil.getUser();
				//取得當前登錄用戶的可處理券商資料
				String userGroupPk = user.getGroup().getGroupPk().toString();
				//取得當前選擇處理券商的資料
				List<String> tempUserGroupPk = new ArrayList<String>();
				tempUserGroupPk.add(userGroupPk);
				/* 調用查詢 */
				try {
					securitiesOptionList = securitiesService.findForSecuritiesListByGroupPks(tempUserGroupPk);
				} catch (Exception e) {
					securitiesOptionList = null;
					logger.debug("Error in getSecuritiesOptionList() method when login user is bank group for find for securities list by group Pk!");
				}
			}
			/* 如果是銀行群組，則可以查詢所有分公司的資料 */
			else{
				/* 調用查詢 */
				securitiesOptionList = securitiesService.findForListBySecurities();
			}
		}
		return securitiesOptionList;
	}

	/**
	 * @param securitiesOptionList 的設定的 securitiesOptionList
	 */
	public void setSecuritiesOptionList(List<Securities> securitiesOptionList) {
		this.securitiesOptionList = securitiesOptionList;
	}
	
	/**
	 * @return confirmIfTemp
	 */
	public String getConfirmIfTemp() {
		return confirmIfTemp;
	}

	/**
	 * @param confirmIfTemp 的設定的 confirmIfTemp
	 */
	public void setConfirmIfTemp(String confirmIfTemp) {
		this.confirmIfTemp = confirmIfTemp;
	}

	/**
	 * @return isBankGroupUser
	 */
	public Boolean getIsBankGroupUser() {
		boolean tempIsBankGroupUser = UserUtil.isBankGroup();
		return tempIsBankGroupUser;
	}
	
	/**
	 * @return qryGroupPk
	 */
	public Long getQryGroupPk() {
		return qryGroupPk;
	}

	/**
	 * @param qryGroupPk 的設定的 qryGroupPk
	 */
	public void setQryGroupPk(Long qryGroupPk) {
		this.qryGroupPk = qryGroupPk;
	}

	/**
	 * @return selectedGroup
	 */
	public List<LabelValue> getSelectedGroup() {
		/* 查詢該角色權限下的用戶 */
        //如果資料清空
        List<LabelValue> selectedGroup = new ArrayList<LabelValue>();
        //是銀行群組--列出該角色下的所有用戶
    	//保存查詢到得用戶
    	List<Group> tempGroup;
    	//去數據庫查詢資料
    	try {
    		tempGroup = groupService.findAllGroup();
		} catch (Exception e) {
			tempGroup = null;
		}
    	//轉化資料為可用數據
    	if(null != tempGroup && tempGroup.size() > 0){
    		LabelValue labelValue;
    		for(int i = 0 ; i < tempGroup.size() ; i++){
    			labelValue = new LabelValue();
    			//顯示為 群組No + 用戶ID  要不然頁面名稱容易混亂，不易區分
    			labelValue.setLabel(tempGroup.get(i).getGroupName());
    			labelValue.setValue(tempGroup.get(i).getGroupPk().toString());
    			selectedGroup.add(labelValue);
        		}
        	}
		return selectedGroup;
	}
	
	/*
	 * 將list轉為String
	 */
    protected String getStringFromList(List<String> lists){
    	String temp = "";
    	if(lists != null && lists.size() > 0 ){
	    	for(int i = 0; i < lists.size();i++){
	    		if(lists.get(i) == null)continue;
	    		if(i == 0 || temp.equals("")){
	    			temp = lists.get(i);    			
	    		}else{
	    			temp += "," + lists.get(i);
	    		}
	    		
	    	}
    	}
    	return temp;
    }
	
	
}
